#include <iostream>

#include "Protocol.hpp"
#include "TcpServer.hpp"
#include "Calculator.hpp"
#include "LogMessage.hpp"

class HandlerMessage
{
public:
    static std::string HandlerRequest(Connect* conn)
    {
        std::string& package = conn->GetInBuffer();
        std::string temp;
        while (Protocol::DeCode(package, &temp))
        {
            // temp为序列化的数据，需要反序列化
            Protocol::Factory fact;
            auto res = fact.BulidRequest();
            res->Deserialization(temp);
            
            // 将res中的数据进行计算
            Calculator::Calculator cal;
            auto response = cal.Compute(res);

            // 获取反序列化结果
            std::string out;
            response->Serialization(&out);
            
            // 添加报头
            Protocol::EnCode(out);

            // 将结果添加到发送缓冲区当中
            conn->GetOutBuffer() += out;
        }

        // 通知发送函数进行数据发送
        conn->_writer(conn);
    }

private:
};